#ifndef CONTROLLER_H
#define CONTROLLER_H

#define EPS 0.000001
#define INF 9999999.9

#include <QObject>
#include <QPoint>
#include <QVector2D>
#include <vector>
#include "point3d.h"

#include "curvendimension.hpp"

class MainWindow;
class Canvas;

typedef CurvePoligonal< real , 3 , Point3D , Vec3 > Curve;

class Controller : public QObject
{
    Q_OBJECT

    MainWindow *mw;
    Canvas *c;

    std::vector<Point3D> sampler;
    std::vector<Point3D> original;

    Curve curve;
    Curve base;

    QPoint rightBegin;
    Point3D baseBegin;
    int baseIndex;
    int lIdx;
    int rIdx;
    float delta;
    bool ready;

    Point3D novoPontoEsquerda;
    int idxNovoPontoEsquerda;

    Point3D novoPontoDireita;
    int idxNovoPontoDireita;

public:
    Controller();

    int indexOfMostClose(const QVector2D&);

    int leftIndexFrom(float delta, int idxBase);
    int rightIndexFrom(float delta, int idxBase);

    void modeling(bool final = false);


private slots:
    void left(QPoint);
    void leftRelease();
    void right(QPoint);
    void rightRelease();
    void draw();
    void linear();
    void chaikin();
    void chaikinSub();
    void super();
};

#endif // CONTROLLER_H
